package com.shu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shu.dao.UserDao;
import com.shu.domain.po.User;
import com.shu.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Queue;

/**
 * Created by shu on 2017/8/14.
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    @Override
    //@Transactional(rollbackFor = Exception.class)
    public void addUser(User user) throws Exception{
        userDao.save(user);
        //throw new Exception("error");
    }

    @Override
    public User findUserByName(String userName){
        User queryUser = new User();
        queryUser.setUsername(userName);
        return userDao.get(queryUser).size() > 0 ? userDao.get(queryUser).get(0) : null;
    }

    @Override
    public Object selectByPage(){
        User user = new User();
        user.setPassword("123123");
        PageHelper.startPage(1, 5);
        List<User> list =  userDao.get(user);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

}
